package com.bulletflash.collision.dispatch 
{
	import flash.geom.Matrix3D;
	import flash.geom.Vector3D;
	
	import com.bulletflash.btBase;
	import com.bulletflash.math.btVector3;
	import com.bulletflash.math.btTransform;
	import com.bulletflash.data.btCollisionFlags;
	
	public class btCollisionObject extends btBase
	{
		public static var ACTIVE_TAG:int = 1;
		public static var ISLAND_SLEEPING:int = 2;
		public static var WANTS_DEACTIVATION:int = 3;
		public static var DISABLE_DEACTIVATION:int = 4;
		public static var DISABLE_SIMULATION:int = 5;
		
		private var m_worldTransform:btTransform;
		private var m_anisotropicFriction:btVector3;
		
		public function btCollisionObject(ptr:uint)
		{
			pointer = ptr;
			
			m_worldTransform = new btTransform(ptr + 4);
			m_anisotropicFriction = new btVector3(ptr + 164);
		}
		
		public function set position(pos:Vector3D):void {
			m_worldTransform.position.sv3d = pos;
		}
		
		public function get position():Vector3D {
			return m_worldTransform.position.sv3d;
		}
		
		public function set rotation(rot:Matrix3D):void {
			m_worldTransform.rotation.m3d = rot;
		}
		
		public function get rotation():Matrix3D {
			return m_worldTransform.rotation.m3d;
		}
		
		public function setWorldTransform(pos:Vector3D, rot:Matrix3D):void {
			m_worldTransform.position.sv3d = pos;
			m_worldTransform.rotation.m3d = rot;
		}
		
		public function get anisotropicFriction():Vector3D {
			return m_anisotropicFriction.v3d;
		}
		
		public function set anisotropicFriction(v:Vector3D):void {
			m_anisotropicFriction.v3d = v;
			hasAnisotropicFriction = (v.x != 1 || v.y != 1 || v.z != 1)?1:0;
		}
		
		public function get friction():Number { return memUser._mrf(pointer + 224); }
		public function set friction(v:Number):void { memUser._mwf(pointer + 224, v); }
		public function get restitution():Number { return memUser._mrf(pointer + 228); }
		public function set restitution(v:Number):void { memUser._mwf(pointer + 228, v); }
		public function get hasAnisotropicFriction():int { return memUser._mr32(pointer + 180); }
		public function set hasAnisotropicFriction(v:int):void { memUser._mw32(pointer + 180, v); }
		public function get contactProcessingThreshold():Number { return memUser._mrf(pointer + 184); }
		public function set contactProcessingThreshold(v:Number):void { memUser._mwf(pointer + 184, v); }
		public function get collisionFlags():int { return memUser._mr32(pointer + 204); }
		public function set collisionFlags(v:int):void { memUser._mw32(pointer + 204, v); }
		public function get islandTag():int { return memUser._mr32(pointer + 208); }
		public function set islandTag(v:int):void { memUser._mw32(pointer + 208, v); }
		public function get companionId():int { return memUser._mr32(pointer + 212); }
		public function set companionId(v:int):void { memUser._mw32(pointer + 212, v); }
		public function get deactivationTime():Number { return memUser._mrf(pointer + 220); }
		public function set deactivationTime(v:Number):void { memUser._mwf(pointer + 220, v); }
		public function get activationState():int { return memUser._mr32(pointer + 216); }
		public function set activationState(newState:int):void {
			if (activationState != btCollisionObject.DISABLE_DEACTIVATION && activationState != btCollisionObject.DISABLE_SIMULATION) {
				memUser._mw32(pointer + 216, newState);
			}
		}
		
		public function forceActivationState(newState:int):void {
			memUser._mw32(pointer + 216, newState);
		}
		
		public function activate(forceActivation:Boolean = false):void {
			if (forceActivation || (collisionFlags != btCollisionFlags.CF_STATIC_OBJECT && collisionFlags != btCollisionFlags.CF_KINEMATIC_OBJECT)) {
				this.activationState = btCollisionObject.ACTIVE_TAG;
				this.deactivationTime = 0;
			}
		}
		
		public function get isActive():Boolean {
			return (activationState != btCollisionObject.ISLAND_SLEEPING && activationState != btCollisionObject.DISABLE_SIMULATION);
		}
	}

}